package com.bdult.vh.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.bdult.vh.common.CommonUtil;
import com.bdult.vh.common.UtilBean;
import com.bdult.vh.service.CommonService;
import com.bdult.vh.service.ItemService;
import com.bdult.vh.service.MemberService;

/**
 * Handles requests for the application home page.
 */
@Controller
public class MemberController {
	
	private static final Logger logger = LoggerFactory.getLogger(MemberController.class);
	
	@Autowired
	private ItemService itemService;
	
	@Autowired
	private CommonService commonService;
	
	@Autowired
	private MemberService memberService;
	
	@RequestMapping(value="/member/login")
	public ModelAndView login(Model model, HttpServletRequest request, HttpSession session) {
		ModelAndView mv = new ModelAndView();
		session.invalidate();
		
		//자동 로그인 체크
		String name   = "";
		String value   = "";
		Cookie[] cookies = request.getCookies();
	    if(cookies != null){
			System.out.println("cookie 수 = " + cookies.length);
	        for (int i = 0; i < cookies.length; i++) {
				  name  = cookies[i].getName();
				  value  = cookies[i].getValue();
				  System.out.println(i + ".COOKIES NAME : " + name + " / VALUE : " + value);
				  
				  if(name.equals("member_id")) {
					  mv.addObject("member_id", value);
				  }
				  if(name.equals("auto_login")) {
					  mv.addObject("auto_login", value);
				  }
				  if(name.equals("member_pwd")) {
					  mv.addObject("member_pwd", value);
				  }
			 }
		}
			    
		mv.setViewName("login");
		return mv;
	}
	
	@RequestMapping(value="/member/logout")
	public ModelAndView logout(Model model, HttpSession session) {
		ModelAndView mv = new ModelAndView();
		session.invalidate();
		mv.setViewName("redirect:/member/login.vh");
		return mv;
	}
	
	@RequestMapping(value="/member/logincheck")
	public ModelAndView logincheck(@RequestParam Map<String, Object> paramMap, HttpSession session, HttpServletResponse response ) {
		String goPage = "";
		String save_id = "";
		String auto_login = "";
		
		String id = paramMap.get("id").toString();
		String pwd = paramMap.get("pwd").toString();
		if( paramMap.get("save_id") != null) save_id = paramMap.get("save_id").toString();
		if( paramMap.get("auto_login") != null) auto_login = paramMap.get("auto_login").toString();
		
		HashMap map = new HashMap<String,String>();
		map.put("id", id);
		pwd = CommonUtil.convertPasswordMD5(CommonUtil.checkNullString(pwd));
		map.put("pwd", pwd);
		
		HashMap result_map = new HashMap<String,String>();
		result_map = memberService.loginCheck(map);

		ModelAndView mv=new ModelAndView();
		if(result_map!=null){
			session.setMaxInactiveInterval(60*30);
			
			session.setAttribute("member_id", result_map.get("CSTMID"));
			session.setAttribute("member_name", result_map.get("CSTMNM"));
			session.setAttribute("cstmno", result_map.get("CSTMNO"));
			session.setAttribute("cstmrank", result_map.get("CSTMGR"));
			
	        session.setAttribute("m_no", UtilBean.checkNullString(result_map.get("CSTMNO"))); 
	        session.setAttribute("m_userid", UtilBean.checkNullString(result_map.get("CSTMID"))); 
	        session.setAttribute("m_email", UtilBean.checkNullString(result_map.get("EMAIL")));     
	        session.setAttribute("m_name", UtilBean.checkNullString(result_map.get("CSTMNM")));   
	        session.setAttribute("m_rank", UtilBean.checkNullString(result_map.get("CSTMGR")));  
	        session.setAttribute("m_accumrate", UtilBean.checkNullString(result_map.get("ACCUMRATE")));  
	        session.setAttribute("m_defaultaccumrate", UtilBean.checkNullString(result_map.get("DEFAULTACCUMRATE")));  
	        session.setAttribute("m_ranknm", UtilBean.checkNullString(result_map.get("CDNM")));  
	        session.setAttribute("m_mobileno", UtilBean.checkNullString(result_map.get("MOBILENO1"))+'-'+UtilBean.checkNullString(result_map.get("MOBILENO2"))+'-'+UtilBean.checkNullString(result_map.get("MOBILENO3")));
	        session.setAttribute("m_di", UtilBean.checkNullString(result_map.get("DI")));
	        session.setAttribute("m_cstmfl", UtilBean.checkNullString(result_map.get("CSTMFL")));
	        session.setAttribute("m_sex", UtilBean.checkNullString(result_map.get("SEX")));

	        session.setAttribute("logintype", "2"); //일반회원로그인2 
			
			//아이디 저장
			Cookie cookie_id = new Cookie("member_id", (String) result_map.get("CSTMID"));
			Cookie cookie_pwd = new Cookie("member_pwd", pwd);
			Cookie cookie_auto_login = new Cookie("auto_login", "Y");
			if(save_id.equals("on") && !auto_login.equals("on")){
				System.out.println("save_id = " + save_id);
				cookie_id.setMaxAge(7*24*60*60);
				cookie_pwd.setMaxAge(0);
				cookie_auto_login.setMaxAge(0);
			} else if(save_id.equals("on") && auto_login.equals("on")){
				System.out.println("save_id = " + save_id);
				System.out.println("*auto_login = " + auto_login);
				cookie_id.setMaxAge(7*24*60*60);
				cookie_pwd.setMaxAge(7*24*60*60);
				cookie_auto_login.setMaxAge(7*24*60*60);
			} else{
				cookie_id.setMaxAge(0);
				cookie_pwd.setMaxAge(0);
				cookie_auto_login.setMaxAge(0);
			}
			
			cookie_id.setPath("/");
			cookie_auto_login.setPath("/");
			cookie_pwd.setPath("/");
			
			response.addCookie(cookie_id);
			response.addCookie(cookie_auto_login);
			response.addCookie(cookie_pwd);
			
			goPage = "redirect:/main.vh";
		} else {
			goPage = "login";

		    mv.addObject("rsltmsg","로그인 정보를 다시 확인하여주십시요.");
		}
	    mv.setViewName(goPage);
	    
	    return mv;
	}
	
	@RequestMapping(value="/member/join1_1")
	public ModelAndView join1_1(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("join1_1");
		return mv;
	}
	
	@RequestMapping(value="/member/join1_2")
	public ModelAndView join1_2(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		
		String goPage = "";
		String rsltmsg = "";
		
		String CSTMNM = (String) paramMap.get("uname");
		String MOBILENO = (String) paramMap.get("uphone");
		String MOBILENO1 = "";
		String MOBILENO2 = "";
		String MOBILENO3 = "";		
		if(MOBILENO!=null) MOBILENO = MOBILENO.trim();
		
		if(MOBILENO.length()==11) {
			MOBILENO1 = MOBILENO.substring(0, 3);
			MOBILENO2 = MOBILENO.substring(3, 7);
			MOBILENO3 = MOBILENO.substring(7);
		}
		
		//전화번호 중복체크
		Map<String,String> map = new HashMap<String, String>();
		map.put("CSTMNM", CSTMNM);
		map.put("MOBILENO1", MOBILENO1);
		map.put("MOBILENO2", MOBILENO2);
		map.put("MOBILENO3", MOBILENO3);
		int isMember = memberService.isMember(map);
		if(isMember > 0) {
			rsltmsg = "이미 회원이십니다.";			
			mv.addObject("rsltmsg", rsltmsg);
			goPage = "join1_1";
		} else {
			goPage = "join1_2";
		}
		
		mv.addObject("data", paramMap);
		mv.setViewName(goPage);
		return mv;
	}
	
	@RequestMapping(value="/member/idFind1_1")
	public ModelAndView idFind1_1(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("idFind1_1");
		return mv;
	}
	
	@RequestMapping(value="/member/idFind1_2")
	public ModelAndView idFind1_2(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		
		String goPage = "";
		String rsltmsg = "";
		
		String CSTMNM = (String) paramMap.get("uname");
		String MOBILENO = (String) paramMap.get("uphone");
		String MOBILENO1 = "";
		String MOBILENO2 = "";
		String MOBILENO3 = "";		
		if(MOBILENO!=null) MOBILENO = MOBILENO.trim();
		
		if(MOBILENO.length()==11) {
			MOBILENO1 = MOBILENO.substring(0, 3);
			MOBILENO2 = MOBILENO.substring(3, 7);
			MOBILENO3 = MOBILENO.substring(7);
		}
		
		//이름/전화번호 중복체크
		Map<String,String> map = new HashMap<String, String>();
		map.put("CSTMNM", CSTMNM);
		map.put("MOBILENO1", MOBILENO1);
		map.put("MOBILENO2", MOBILENO2);
		map.put("MOBILENO3", MOBILENO3);
		int isMember = memberService.isMember(map);
		if(isMember > 0) {
			goPage = "idFind1_2";
		} else {
			rsltmsg = "회원이 아닙니다.";			
			mv.addObject("rsltmsg", rsltmsg);
			goPage = "idFind1_1";
		}
		
		mv.addObject("data", paramMap);
		mv.setViewName(goPage);
		return mv;
	}
	
	@RequestMapping(value="/member/pwFind1_1")
	public ModelAndView pwFind1_1(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("pwFind1_1");
		return mv;
	}
	
	@RequestMapping(value="/member/pwFind1_2")
	public ModelAndView pwFind1_2(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		
		String goPage = "";
		String rsltmsg = "";
		
		String CSTMID = (String) paramMap.get("cstmid");
		String CSTMNM = (String) paramMap.get("uname");
		String MOBILENO = (String) paramMap.get("uphone");
		String MOBILENO1 = "";
		String MOBILENO2 = "";
		String MOBILENO3 = "";		
		if(MOBILENO!=null) MOBILENO = MOBILENO.trim();
		
		if(MOBILENO.length()==11) {
			MOBILENO1 = MOBILENO.substring(0, 3);
			MOBILENO2 = MOBILENO.substring(3, 7);
			MOBILENO3 = MOBILENO.substring(7);
		}
		
		Map<String,String> map = new HashMap<String, String>();
		map.put("CSTMID", CSTMID);
		map.put("CSTMNM", CSTMNM);
		map.put("MOBILENO1", MOBILENO1);
		map.put("MOBILENO2", MOBILENO2);
		map.put("MOBILENO3", MOBILENO3);
		int isMember = memberService.isMember2(map);
		if(isMember > 0) {
			goPage = "pwFind1_2";
		} else {
			rsltmsg = "입력하신 정보가 일치하지 않습니다.";			
			mv.addObject("rsltmsg", rsltmsg);
			goPage = "pwFind1_1";
		}
		
		mv.addObject("data", paramMap);
		mv.setViewName(goPage);
		return mv;
	}
	
	@RequestMapping(value="/member/join2")
	public ModelAndView join2(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("data", paramMap);
		mv.setViewName("join2");
		
		return mv;
	}
	
	@RequestMapping(value="/member/joinComplete")
	public ModelAndView joinComplete(Model model, @RequestParam Map<String, Object> paramMap) throws Exception {
		ModelAndView mv = new ModelAndView();
		System.out.println("paramMap : " + paramMap);
		
		String MOBILENO = (String) paramMap.get("join_phone");
		String MOBILENO1 = "";
		String MOBILENO2 = "";
		String MOBILENO3 = "";		
		if(MOBILENO!=null) MOBILENO = MOBILENO.trim();
		
		if(MOBILENO.length()==11) {
			MOBILENO1 = MOBILENO.substring(0, 3);
			MOBILENO2 = MOBILENO.substring(3, 7);
			MOBILENO3 = MOBILENO.substring(7);
		}
		
		String zipcode1 = paramMap.get("join_addr_zipcode1").toString();
		String zipcode2 = paramMap.get("join_addr_zipcode2").toString();
		String zipcode = zipcode1 + "-" + zipcode2;
		System.out.println("zipcode = " + zipcode + " : " + zipcode1 + "-" + zipcode2);		
		
		String pwd = paramMap.get("join_pw").toString();
		System.out.println("pwd = " + pwd);
		pwd = CommonUtil.convertPasswordMD5(CommonUtil.checkNullString(pwd));
		System.out.println("md5 pwd = " + pwd);
		
		String birthYYYY = paramMap.get("join_birth_yyyy").toString();
		String birthMM = paramMap.get("join_birth_mm").toString();
		if(birthMM.length()==1) birthMM = "0" + birthMM;
		String birthDD = paramMap.get("join_birth_dd").toString();
		if(birthDD.length()==1) birthDD = "0" + birthDD;
		String birthDate = birthYYYY + birthMM + birthDD;
		System.out.println("birthDate = " + birthDate + " : " + birthYYYY + "/" + birthMM + "/" + birthDD);
		
		long iCSTMNO = 0L;
		iCSTMNO = getMaxNumber("TBLMEMBER.CSTMNO", true);
		
		Map<String, Object> insertData = new HashMap<String, Object>();
		/*
		 * #{CSTMNO}, #{CSTMNM}, #{CSTMID}, #{PSWD}, #{SEX}                       
	      , #{EMAIL}, #{EMAILRECV}
	      , #{HOMEPHONENO1}, #{HOMEPHONENO2}, #{HOMEPHONENO3}
	      , #{MOBILENO1}, #{MOBILENO2}, #{MOBILENO3}                 
	      , #{COPHONENO1}, #{COPHONENO2}, #{COPHONENO3}                
	      , #{SMSRECV}, #{HOMECOCL}, #{POSTRECV}
	      , #{HOMEZIPCODE}, #{HOMEADDR1}, HOMEADDR2}                 
	      , #{COZIPCODE}, #{COADDR1}, #{COADDR2}                   
	      , #{BRTHDATE}, #{WEDFL}, #{WEDDATE}, #{JOB}, #{CONCCAT}                         
	      , #{ALIENCL}, #{CSTMGR}, #{DROPOUTFL}, #{DI}, #{SHOWRECV}                  
	      , #{CSTMFL}, #{REGID}, #{UPDID}
		 */
		insertData.put("CSTMNO", iCSTMNO);
		insertData.put("CSTMNM", paramMap.get("join_name"));
		insertData.put("CSTMID", paramMap.get("join_id"));
		insertData.put("PSWD", pwd);
		insertData.put("SEX", paramMap.get("join_sex"));
		insertData.put("EMAIL", paramMap.get("join_email") );
		insertData.put("EMAILRECV", paramMap.get("emailrecv"));
		insertData.put("HOMEPHONENO1", paramMap.get("homephoneno1"));
		insertData.put("HOMEPHONENO2", paramMap.get("homephoneno2"));
		insertData.put("HOMEPHONENO3", paramMap.get("homephoneno3"));
		insertData.put("MOBILENO1", MOBILENO1);
		insertData.put("MOBILENO2", MOBILENO2);
		insertData.put("MOBILENO3", MOBILENO3);		
		insertData.put("COPHONENO1", "");
		insertData.put("COPHONENO2", "");
		insertData.put("COPHONENO3", "");
		insertData.put("SMSRECV", paramMap.get("smsrecv"));
		insertData.put("HOMECOCL", "H");	//회사자택 구분
		insertData.put("POSTRECV", paramMap.get("postrecv"));
		
		insertData.put("HOMEZIPCODE", zipcode);
		insertData.put("HOMEADDR1", paramMap.get("join_addr1"));
		insertData.put("HOMEADDR2", paramMap.get("join_addr2"));
		insertData.put("COZIPCODE", "");
		insertData.put("COADDR1", "");
		insertData.put("COADDR2", "");
		insertData.put("BRTHDATE", birthDate);
		insertData.put("WEDFL", "N");
		insertData.put("WEDDATE", "");
		insertData.put("JOB", "");
		insertData.put("CONCCAT", "");
		insertData.put("ALIENCL", "D");		
		insertData.put("CSTMGR", "MG0101");	//회원등급 - MD01 온라인회원, MD02 전화회원, MD03 비회원
		insertData.put("DROPOUTFL", "N");	//탈퇴여브
		
		insertData.put("DI", "");			//****가입중복값  iPin에서 가져오는게 아닌지? 일단 비움
		
		insertData.put("SHOWRECV", "Y");	//쇼타임
		
		insertData.put("CSTMFL", "MD01");		//회원구분
		insertData.put("REGID", iCSTMNO);
		insertData.put("UPDID", iCSTMNO);
	System.out.println("insertData = " + insertData);
		int rval = memberService.insertMember(insertData);
		String rsltMsg = "가입실패";
		if(rval>0) rsltMsg = "가입이 완료되었습니다.";
		mv.addObject("rsltmsg", rsltMsg);
		mv.setViewName("redirect:/main.vh");
		
		return mv;
	}
	
	@RequestMapping(value="/member/smscert")
	public ModelAndView smscert(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		boolean isMatch = false;		
		String rsltMsg = "";
		String goPage ="join2";
		String certno = (String)paramMap.get("certno");
		
		if(certno.equals("1234")) isMatch = true;
			
		if(!isMatch){
			rsltMsg = "인증 실패 인증번호를 확인하여 주세요. ";
			goPage = "join1_2";
			mv.addObject("rsltmsg", rsltMsg);
		}
		
		mv.addObject("data", paramMap);
		mv.setViewName(goPage);
		return mv;
	}
	
	@RequestMapping(value="/member/smscert_idfind")
	public ModelAndView smscert_idfind(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		boolean isMatch = false;		
		String rsltMsg = "";
		String goPage = "idFind_result";
		String certno = (String)paramMap.get("certno");
		
		if(certno.equals("1234")) isMatch = true;
			
		if(!isMatch){
			rsltMsg = "인증 실패 인증번호를 확인하여 주세요. ";
			goPage = "idFind1_2";
			mv.addObject("rsltmsg", rsltMsg);
		} else {
			Map<String,String> map = new HashMap<String, String>();
			
			String CSTMNM = (String) paramMap.get("uname");
			String MOBILENO = (String) paramMap.get("uphone");
			String MOBILENO1 = "";
			String MOBILENO2 = "";
			String MOBILENO3 = "";		
			if(MOBILENO!=null) MOBILENO = MOBILENO.trim();
			
			if(MOBILENO.length()==11) {
				MOBILENO1 = MOBILENO.substring(0, 3);
				MOBILENO2 = MOBILENO.substring(3, 7);
				MOBILENO3 = MOBILENO.substring(7);
			}
			
			map.put("CSTMNM", CSTMNM);
			map.put("MOBILENO1", MOBILENO1);
			map.put("MOBILENO2", MOBILENO2);
			map.put("MOBILENO3", MOBILENO3);
			System.out.println("**** map = " + map);
			Map<String, Object> getMemberData = memberService.getMemberData(map);
			System.out.println("**** getMemberData = " + getMemberData);
			
			paramMap.put("cstmid", getMemberData.get("CSTMID"));
		}
		 
		mv.addObject("data", paramMap);
		mv.setViewName(goPage);
		return mv;
	}
	
	@RequestMapping(value="/member/smscert_pwfind")
	public ModelAndView smscert_pwfind(Model model, @RequestParam Map<String, Object> paramMap) {
		ModelAndView mv = new ModelAndView();
		boolean isMatch = false;		
		String rsltMsg = "";
		String goPage = "pwFind_result";
		String certno = (String)paramMap.get("certno");
		
		if(certno.equals("1234")) isMatch = true;
			
		if(!isMatch){
			rsltMsg = "인증 실패 인증번호를 확인하여 주세요. ";
			goPage = "pwFind1_2";
			mv.addObject("rsltmsg", rsltMsg);
		} else {
			Map<String,String> map = new HashMap<String, String>();
			
			String CSTMNM = (String) paramMap.get("uname");
			String MOBILENO = (String) paramMap.get("uphone");
			String MOBILENO1 = "";
			String MOBILENO2 = "";
			String MOBILENO3 = "";		
			if(MOBILENO!=null) MOBILENO = MOBILENO.trim();
			
			if(MOBILENO.length()==11) {
				MOBILENO1 = MOBILENO.substring(0, 3);
				MOBILENO2 = MOBILENO.substring(3, 7);
				MOBILENO3 = MOBILENO.substring(7);
			}
			
			map.put("CSTMNM", CSTMNM);
			map.put("MOBILENO1", MOBILENO1);
			map.put("MOBILENO2", MOBILENO2);
			map.put("MOBILENO3", MOBILENO3);
			System.out.println("**** map = " + map);
			Map<String, Object> getMemberData = memberService.getMemberData(map);
			
			paramMap.put("cstmid", getMemberData.get("CSTMID"));
		}
		 
		mv.addObject("data", paramMap);
		mv.setViewName(goPage);
		return mv;
	}
	
	@RequestMapping(value="/member/pwFind_complete")
	public ModelAndView pwFind_complete(Model model, @RequestParam Map<String, Object> paramMap, HttpSession session) {
		ModelAndView mv = new ModelAndView();
		String rsltmsg = "";
		
		//비밀번호 변경
		String pswd = (String)paramMap.get("pswd");
		pswd = CommonUtil.convertPasswordMD5(CommonUtil.checkNullString(pswd));
		paramMap.put("PSWD", pswd);	
		paramMap.put("CSTMID", paramMap.get("cstmid"));
		System.out.println("**** paramMap = " + paramMap);
		int rval = memberService.updateMemberPSWD(paramMap);
		if(rval>0) {
			rsltmsg = "비밀번호가 변경되었습니다.";
		} else {
			rsltmsg = "비밀번호 변경에 실패하였습니다.";
		}
		
		mv.addObject("rsltmsg", rsltmsg);
		mv.setViewName("redirect:/main.vh");
		return mv;
	}
	
	@RequestMapping(value="/member/idcheck")
	public String idcheck(Model model, @RequestParam("id")String id) {
		int cnt = memberService.idCheck(id);
		
			
		if(cnt>0){
			model.addAttribute("result", 400);
		}else{
			model.addAttribute("result", 200);
		}
		return "jsonView";
	}
	
	@RequestMapping(value="/member/tal1")
	public ModelAndView tal1(Model model) {
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("tal1");
		return mv;
	}
	
	@RequestMapping(value="/member/tal2")
	public ModelAndView tal2(Model model, @RequestParam Map<String,Object> paramMap, HttpSession session) {
		ModelAndView mv = new ModelAndView();
		//아이디 비번 체크
		String goPage = "redirect:/member/tal1.vh";
		String save_id = "";
		String auto_login = "";
		String rsltmsg = "";
		
		String cstmid = paramMap.get("cstmid").toString().trim();
		String pswd = paramMap.get("pswd").toString().trim();
		
		//입력한 아이디와 패스워가 같은지 체크
		System.out.println("session member_id = " + session.getAttribute("member_id")  + " / cstmid = " + cstmid);
		if(cstmid.equals( session.getAttribute("member_id") )) {
			System.out.println("아이디 일치");
			
			HashMap map = new HashMap<String,String>();
			map.put("id", cstmid);
			System.out.println("***** pswd [" + pswd + "]");
			pswd = CommonUtil.convertPasswordMD5(CommonUtil.checkNullString(pswd));
			map.put("pwd", pswd);
			
			System.out.println("***** " + map);
			HashMap result_map = new HashMap<String,String>();
			result_map = memberService.loginCheck(map);
			System.out.println("***** " + result_map);
			if(result_map!=null){
				
				goPage = "tal2";
			} else {
				mv.addObject("rsltmsg","로그인 정보를 다시 확인하여주십시요.");
			}
		} else {
			System.out.println("아이디 불일치");
			rsltmsg = "현재 로그인한 아이디와 입력하신 아이디가 일치하지 않습니다.";
			mv.addObject("rsltmsg", rsltmsg);
		}
		
		
	    mv.setViewName(goPage);
	    
	    return mv;
	}
	
	@RequestMapping(value="/member/id_find")
	public ModelAndView id_find(Model model) {
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("tal");
		return mv;
	}
	
	@RequestMapping(value="/member/pw_find")
	public ModelAndView pw_find(Model model) {
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("tal");
		return mv;
	}
	
	@RequestMapping(value="/member/talComplete")
	public ModelAndView talComplete(Model model, HttpSession session, @RequestParam Map<String,Object> paramMap) {
		ModelAndView mv = new ModelAndView();	
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("UPDID", session.getAttribute("member_id"));
	
		java.math.BigDecimal icstmno = (java.math.BigDecimal) session.getAttribute("cstmno");
		map.put("CSTMNO", icstmno );
	System.out.println("paramMap = " + paramMap);
		map.put("DROPREASON", paramMap.get("dropreason"));
		map.put("DROPREASONETC", paramMap.get("dropreasonetc"));
	System.out.println("map = " + map);
		int rval = memberService.dropMember(map);
		
		String rsltMsg = "탈퇴실패";
		if(rval>0) rsltMsg = "탈퇴가 완료되었습니다.";
		mv.addObject("rsltmsg", rsltMsg);
		session.invalidate();
		mv.setViewName("login");
		return mv;
	}
	
	/**
	   * tblSequence의 keyID와 일치하는 keyNo의 최대값 +1 반환
	   * 
	   * @param sKeyID : tblSequence의 keyID
	   * @return long
	   * @Author 황세원
	   */
	  private long getMaxNumber(String sKeyID, boolean flag) throws Exception {
		  long iKeyNo = -1;
	    
	      if (flag) {
	    	  
	    	  int iAffected = 0;
	    	  iAffected = commonService.updateSequence(sKeyID);
	    	  if (iAffected <= 0) {
	    		  commonService.insertSequence(sKeyID);
	    	  }
	      }
	      
	      iKeyNo = commonService.selectSequence(sKeyID);;
	      
	      return iKeyNo;
	  }
}
